package com.kun.stringtofile.control;

import com.kun.stringtofile.service.GetStringOfFile;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.io.IOException;

@RestController
@RequestMapping(value = "/home")
public class HomeControl {

    @Resource(name = "fileService")
    private GetStringOfFile fileService;

    @RequestMapping(value = {"/file/{value}","/file"})
    public String downFile(@PathVariable(required = false) String value) throws IOException {
        return fileService.getFileString(value);
    }

    @ExceptionHandler
    public String exceptionHandle(Exception e){
        return e.getMessage();
    }
}
